var /**
	 * 仿真流程管理
	 */
TeachFlow = cc.Class.extend({
	step:0,
	flow:null,
	main:null,
	over_flag: false,
	curSprite:null,
	ctor: function(){
		this.init();
	},
	setMain:function(main){
		this.main=main;
	},
	init: function(){
		for(var i in teach_flow){
			teach_flow[i].finish = false;
			teach_flow[i].cur = false;
			if(teach_flow[i].action == null){
				teach_flow[i].action = ACTION_NONE;
			}
		}
	},
	start:/**
			 * 开始流程
			 */
	function(){
		this.over_flag = false;
		this.step = 0;
		
		/* 新标准，开始的时候，执行下一步 */
		this.next();
	},
	over:/**
			 * 流程结束，计算分数，跳转到结束场景，
			 */
	function(){
		this.over_flag = true;
		this.flow = over;
		gg.lastStep = this.step;
		this.main.over();
	},
	checkTag:/**
				 * 检查是否当前步骤
				 * 
				 * @deprecated 使用新Angel类，不再判断是否当前步骤
				 * @param tag
				 * @returns {Boolean}
				 */
	function(tag){
		var cur_flow = teach_flow[this.step - 1];
		if(cur_flow.tag == tag){
			return true;
		} else {
			return false;
		}
	},
	prev:/**
			 * 回退一定步数
			 * 
			 * @deprecated 需结合具体实现，，暂时不再启动
			 * @param count
			 *            步数
			 */
	function(count){
		if(this.curSprite!=null){
			this.curSprite = null;
		}
		if(this.flow!=null){
			this.flow.cur = false;
		}
		this.step = this.step - count;
		this.flow = teach_flow[this.step - 1];
		this.refresh();
		gg.score -= 11;
	},
	next:/**
			 * 执行下一步操作， 定位当前任务
			 */
	function(){
		if(this.over_flag){
			return;
		}
		if(this.curSprite!=null){
			this.curSprite.setEnable(false)
			this.curSprite = null;
		}
		if(this.flow!=null){
			this.flow.cur = false;
			// 标记任务已完成
			this.flow.finish = true;
		}
		this.flow = teach_flow[this.step++];
		if(this.flow.finish){
			// 如果任务已完成，跳过当前步骤
			this.next();
		}
		this.refresh();
	},
	refresh:/**
			 * 刷新当前任务状态，设置闪现，点击等状态
			 */
	function(){
		// 刷新提示
		this.flow.cur = true;
		if(this.flow.tip != null){
			ll.tip.tip.doTip(this.flow.tip);
		}
		if(this.flow.flash != null){
			ll.tip.flash.doFlash(this.flow.flash);
		}
		if(this.step > teach_flow.length - 1){
			this.over();
		}
		this.initCurSprite();
		if(this.curSprite!=null){
			this.location();
			this.curSprite.setEnable(true);
		}
	},
//	location:/**
//	 * 定位箭头
//	 */
//		function(){
//		var tag = gg.flow.flow.tag;
//		if(tag instanceof Array){
//			tag=tag[1];
//			if(TAG_LIB_MIN < tag[1]){
//				if(ll.run.lib.isOpen()){
//					ll.tip.arr.pos(this.curSprite);
//				}else{
//					ll.tip.arr.pos(ll.tool.getChildByTag(TAG_BUTTON_LIB));
//				}
//			}else{
//				ll.tip.arr.pos(this.curSprite);
//			}
//		}
//		else {
//			ll.tip.arr.pos(this.curSprite);
//		}		
//	},
	location:/**
	 * 定位箭头
	 */
		function(){
		var tag = gg.flow.flow.tag;
		if(tag instanceof Array){
			if(TAG_LIB_MIN < tag[1]){
				if(ll.run.lib.isOpen()){
					ll.tip.arr.pos(this.curSprite,gg.flow.flow.X,gg.flow.flow.Y);
				}else{
					ll.tip.arr.pos(ll.tool.getChildByTag(TAG_BUTTON_LIB));
				}
			}else{
				ll.tip.arr.pos(this.curSprite,gg.flow.flow.X,gg.flow.flow.Y);
			}
		}
		else {
			ll.tip.arr.pos(this.curSprite,gg.flow.flow.X,gg.flow.flow.Y);
		}		
	},
	getStep:/**
			 * 获取当前步数
			 * 
			 * @returns {Number}
			 */
	function(){
		return this.step;
	},
	initCurSprite:/**
					 * 遍历获取当前任务的操作对象
					 */
	function(){
		var tag = this.flow.tag;
		if(tag == null || tag == undefined){
			return;
		}
		var root = ll.run;
		var sprite = null;
		if(tag == TAG_BUTTON_LIB){
			sprite = ll.tool.getChildByTag(tag);
		} else if(tag instanceof Array){
			// 数组
			for (var i in tag) {
				root = root.getChildByTag(tag[i]);
			}
			sprite = root;
		} else {
			// 单个tag
			var sprite = root.getChildByTag(tag);
		}
		if(sprite != null){
			this.curSprite = sprite;
			return;
		}
	}
});
// 任务流
teach_flow = [
// 取5g粗食盐
	{tip:"1.打开物品库",tag:TAG_BUTTON_LIB},
	{tip:"取出量筒1",tag:[TAG_LIB,TAG_LIB_CYLINDER],action:ACTION_DO1},
	{tip:"取出装有生理盐水的试剂瓶",tag:[TAG_LIB,TAG_LIB_BOTTLE]},
	{tip:"打开试剂瓶",tag:[TAG_BOTTLE_ALL,TAG_LID]},
	{tip:"将试剂瓶中生理盐水倒入量筒中,直至达到25ml刻度线",tag:[TAG_BOTTLE_ALL,TAG_BOTTLE]},
	{tip:"取出量筒2",tag:[TAG_LIB,TAG_LIB_CYLINDER],action:ACTION_DO2},
	{tip:"取出蒸馏水瓶",tag:[TAG_LIB,TAG_LIB_KETTLE]},
	{tip:"将蒸馏水倒入量筒中直至达到25ml刻度线",tag:[TAG_KETTLE_ALL,TAG_KETTLE]},
	{tip:"取出烧杯",tag:[TAG_LIB,TAG_LIB_BEAKER]} ,
	{tip:"将量筒1中液体移入烧杯中",tag:[TAG_CYLINDER_ALL,TAG_CYLINDER]},
	{tip:"将量筒2中液体移入烧杯中",tag:[TAG_CYLINDER1_ALL,TAG_CYLINDER]},
	{tip:"取出玻璃棒搅拌烧杯中溶液使溶液混合均匀",tag:[TAG_LIB,TAG_LIB_ROD]},
	{tip:"取出锥形瓶",tag:[TAG_LIB,TAG_LIB_FLASK]},
	{tip:"取出移液管,用移液管移取25ml稀释后的生理盐水,到锥形瓶中",tag:[TAG_LIB,TAG_LIB_PIPETTE]},
	{tip:"取出K2CrO4指示剂",tag:[TAG_LIB,TAG_LIB_K]},
	{tip:"打开K2CrO4指示剂瓶",tag:[TAG_K2CrO4_ALL,TAG_K2CrO4,TAG_LID1]},
	{tip:"取出移液管,移取1ml的K2CrO4指示剂,将移液管中的K2CrO4指示剂倒入锥形瓶中",tag:[TAG_LIB,TAG_LIB_PIPETTE1]},
	{tip:"取出铁架台",tag:[TAG_LIB,TAG_LIB_IRONSHELF]},
	{tip:"将锥形瓶放在铁架台上",tag:[TAG_FLASK_ALL,TAG_FLASK]},
	{tip:"取出酸式滴定管",tag:[TAG_LIB,TAG_LIB_BURET]},
	{tip:"取出AgNO3标准溶液(0.1mol/L)",tag:[TAG_LIB,TAG_LIB_BOTTLE1]},
	{tip:"打开瓶盖",tag:[TAG_BOTTLE1_ALL,TAG_LID2]},
	{tip:"将AgNo3标准溶液加入到酸式滴定管中,查看并记录初始刻度",tag:[TAG_BOTTLE1_ALL,TAG_BOTTLE1]},
	{tip:"将酸式滴定管架在铁架台上",tag:[TAG_BURET_ALL,TAG_BURET]},
	{tip:"打开酸式滴定管开关进行滴定,直到锥形瓶中出现砖红色沉淀",tag:[TAG_BURET_ALL,TAG_BURET,TAG_OPEN],action:ACTION_DO1},
	{tip:"关闭酸式滴定管开关",tag:[TAG_BURET_ALL,TAG_BURET,TAG_OPEN],action:ACTION_DO2},
	{tip:"恭喜过关",over:true}
];
over = {tip:"恭喜过关"};



